import { defineStore } from 'pinia';
import axios from 'axios';
export const blog = defineStore('blog', {
	state: () => {
		return {
			// name: '李浩明',
			// age: 23,
			blogId: 0,
			searchState: '',
			searchVal: '',
			data: null,
			total: 5,
		};
	},
	getters: {
		// changeAge() {
		// 	return this.age + 1;
		// },
	},
	actions: {
		async getUserBlog(uploader) {
			if (uploader) {
				try {
					const res = await axios({
						baseURL: 'http://localhost:5000',
						url: '/getUserBlog',
						method: 'post',
						data: {
							uploader,
						},
					});
					if (res.data.state === 'ok') {
						return res.data.data;
					} else {
						return res.data.state;
					}
				} catch (error) {
					return 'error';
				}
			} else {
				return 'error';
			}
		},
		stripHtmlTags(htmlString) {
			return htmlString.replace(/<[^>]*>?/gm, '');
		},
	},
	persist: {
		enabled: true, // true 表示开启持久化保存
	},
});
